package io.github.quickmsg.interate.sharedstrategy;

import cn.hutool.core.collection.ListUtil;
import org.apache.commons.lang3.tuple.ImmutableTriple;

import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author Zander.Wu
 */
public class RandomStrategy implements SharedStrategy{

    @Override
    public ImmutableTriple<String, String, String> searchSharedSubscribe(Set<ImmutableTriple<String, String, String>> shareSubscribes, String consistentId) {
        List<ImmutableTriple<String, String, String>> subscribes = ListUtil.toList(shareSubscribes);
        Random random = ThreadLocalRandom.current();
        int length = subscribes.size();
        return subscribes.get(random.nextInt(length));
    }
}
